﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

/// <summary>
///WebService 的摘要说明
/// </summary>
//[WebService(Namespace = "http://tempuri.org/")]
//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
 [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
     [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
     //方法不可宣告static
     public string[] GetCompletionList(string prefixText, int count)
     {
         //資料庫連線字串
         Datacon dataconn = new Datacon();
         SqlConnection cn = dataconn.getcon();
         
         
 
         ArrayList array = new ArrayList();//儲存撈出來的字串集合

         //using (SqlConnection conn = new SqlConnection(connStr))
         {
             DataSet ds = new DataSet();
             string selectStr = @"SELECT Top (" + count + ") danweimingchen FROM danwei Where danweimingchen Like '%" + prefixText + "%' Order by danweimingchen ASC";
             SqlDataAdapter da = new SqlDataAdapter(selectStr, cn);
             cn.Open();
             da.Fill(ds);
             foreach (DataRow dr in ds.Tables[0].Rows)
             {
                 array.Add(dr["danweimingchen"].ToString());
             }

         }
         cn.Close();

         return (string[])array.ToArray(typeof(string));

     }
 

     
     
     public WebService () {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
    
}
